<template>
  <!-- 选择配送方式  -->
  <div>
    <van-action-sheet v-model="show" :actions="actions"
      cancel-text="取消"
      description="选择配送方式"
      close-on-click-action
      @select="onSelect"
    >
    </van-action-sheet>
  </div>
</template>

<script>
import { getShopDetails } from '@/api/shops.js'

export default {
  data () {
    return {
      show: this.deliveryshow,
      actions: [
        { name: '超出配送范围' }
      ],
      deliveries: [],
      deliver: {}
    }
  },
  props: {
    deliveryshow: {
      type: [Boolean, String, Object]
    },
    shopId: {
      type: [Number]
    }
  },
  created () {
    this.loadshow()
  },
  mounted () {

  },
  methods: {
    async loadshow() {
      try {
        const { data } = await getShopDetails(this.shopId || 39)
        console.log(data.data.sh_deliveries.length === 0)
        this.deliver = data.data.sh_deliveries
        if (data.data.sh_deliveries.length === 0) {
          this.load()
        }
        this.deliver.forEach(item => {
          this.actions.unshift({
            name: item.delivery_way_name,
            subname: item.start_price,
            way: item.delivery_way
          })
        })
        // console.log(this.deliveries)

        console.log(this.actions)
      } catch (err) {
        this.$toast('数据获取失败')
      }
    },
    async load() {
      try {
        const res = await getShopDetails(36)
        this.deliver = res.data.data.sh_deliveries
      } catch (error) {
        this.$toast('数据获取失败')
      }
    },
    onSelect(item) {
      // 默认情况下点击选项时不会自动收起
      // 可以通过 close-on-click-action 属性开启自动收起

      // this.$emit('deliveryshow', false)
      this.$emit('item', item) // 选中的配送方式
      console.log(item)
    }
  }
}
</script>

<style scoped lang="less">

</style>
